/*
 * @Author: 周鹏飞
 * @Date: 2021-06-12 14:29:55
 * @LastEditors: 周鹏飞
 * @LastEditTime: 2021-07-05 10:33:49
 * @Description: file content
 */
// 获取事件类型列表
function getEventList() {
  $.ajax({
    type: 'GET',
    url: httpUrl + 'event/manager/exigencyEvent/list',
    data: {
      pageSize: 99999
    },
    dataType: 'json',
    contentType: "application/json",
    headers: {
      Authorization: localStorage.getItem('token')
    },
    success: function (data) {
      if (data.code == 200) {
        // console.log(data);

        vm.EventList = data.rows
      }
    },
    error: function (err) {
      // 失败的回调
      vm.$message({
        message: '查询失败请稍后再试,或与管理员联系',
        type: 'error'
      });
    }
  })
}
// 获取当前警情事件
function eventListadd() {
  $.ajax({
    type: 'get',
    url: httpUrl + 'event/manager/event/list',
    data: {},
    dataType: 'json',
    contentType: "application/json",
    headers: {
      Authorization: localStorage.getItem('token')
    },
    success: function (data) {
      // console.log(data)
      if (data.code == 200) {
        vm.EmergencyList = data.rows;
        vm.map.centerAndZoom(new BMap.Point(111.989235, 32.790482), 11);
        alarmListMap(data.rows)
      }
    },
    error: function (err) {
      vm.$message({
        message: '查询失败请稍后再试,或与管理员联系',
        type: 'error'
      });
    }
  })
}

// 处理事件函数
function alarmListMap(data) {
  // console.log(data)
  for (let val of data) {
    // 点位
    console.log(val);
    var point = new BMap.Point(val.longitude, val.latitude)
    // 设置弹出信息位置
    // var latCenter=parseFloat(val.latitude)+0.1
    // console.log(latCenter);
    // var centerPonit=new BMap.Point(val.longitude, latCenter)
    // 创建事件图标
    var myIcon = null;


    switch (val.eStatus) {
      case '0':
        myIcon = new BMap.Icon("./images/red.gif", new BMap.Size(20, 20));
        break;
      case '1':
        myIcon = new BMap.Icon("./images/yellow.gif", new BMap.Size(20, 20));
        break;
      case '2':
        myIcon = new BMap.Icon("./images/blue.gif", new BMap.Size(20, 20));
        break;

      default:
        break;
    }

    // 点位
    var marker = new BMap.Marker(point, { icon: myIcon });
    // 覆盖物标识
    marker.init = 'alarmListmap';
    vm.map.addOverlay(marker);

    // 事件标题
    let name = ''
    for (let [key, vals] of Object.entries(vm.EventList)) {
      // console.log(vals);
      if (vals.id == val.eType) {
        name = vals.eventName
        break;
      }
    }


    var title = `
          <div style='width: auto; height: 22px; padding: 2px 5px; line-height: 22px; text-align: center;border:6px'>
            ${name}
          </div>
        `
    var Distance = name.length * 10;

    var opts = {
      position: point,    // 指定文本标注所在的地理位置
      offset: new BMap.Size(-Distance, 10)    //设置文本偏移量
    }

    let label = new BMap.Label(title, opts);  // 创建文本标注对象
    label.init = "alarmListmap"
    label.setStyle({
      color: "#000",       //文本颜色
      fontSize: "14px",
      lineHeight: "24px",
      fontFamily: "微软雅黑",
      border: "0",
      borderRadius: '6px'
    });

    if (name) {
      vm.map.addOverlay(label);
    }
    var content = `
          <div class="MonitoringStyEvent">
            <div class="MonitoringStyEvent-title">事件信息</div>
            <div class="MonitoringStyEvent-content">
              <div class="MonitoringStyEvent-text">
                <span>事件标题</span>: <p>${name ? name : ''}</p>
              </div>
              <div class="MonitoringStyEvent-text">
                <span>发生地</span>: <p>${val.address ? val.address : ''}</p>
              </div>
	            <div class="MonitoringStyEvent-text">
	              <span>道路方向</span>: <p>${val.direction ? val.direction : ''}</p>
	            </div>
              <div class="MonitoringStyEvent-text">
                <span>来源</span>: <p>${val.source ? val.source : ''}</p>
              </div>
              <div class="MonitoringStyEvent-text">
                <span>时间</span>: <p>${val.eCreateTime ? val.eCreateTime : ''}</p>
              </div>
              <div class="MonitoringStyEvent-text">
                <span>详情</span>: <p>${val.details ? val.details : ''}</p>
              </div>
              <img class="MonitoringStyEvent-img" src="${urlimgadd(val.spareList) ? urlimgadd(val.spareList) : './images/luzheng.jpg'
            }"  alt="暂无图片">
              <div class="EventDetails" onclick="EventDetailsadd()">
                详情
              </div>
            </div>
          </div >
        `

    addClickHandler(content, marker, 'alarmListmap', val, point) // 监控信息窗口
  }
}
function EventDetailsadd() {
  // 显示事件详情
  vm.eventstate = true;
  // 事件详情赋值
  vm.eventForm = vm.Earlywarning
}
